//
//  Chidren.m
//  demo
//
//  Created by chenzm on 2018/8/17.
//  Copyright © 2018年 chenzm. All rights reserved.
//

#import "Chidren.h"

@interface Chidren()
///定时器
@property(nonatomic,strong)NSTimer *timer;

@end


@implementation Chidren

- (id) init{
    self = [super init];
    if(self != nil){
        self.hapyValue= 100;
        [self addTimer];
    }
    return self;
}

///添加定时器
-(void)addTimer{
    //启动定时器
    [self timer];
}

- (void)timerAction:(NSTimer *)timer{
    //使用set方法修改属性值，才能触发KVO
    NSInteger value = _hapyValue;
//    [self setHapyValue:--value];
    self.hapyValue = --value;
    NSInteger values = _hurryValue;
    [self setHurryValue:--values];
}

///注销定时器
-(void)deallocTimer{
    [_timer invalidate];
    _timer = nil;
}

-(void)dealloc{
    [self deallocTimer];
}

#pragma mark - lazyload
-(NSTimer *)timer{
    if (!_timer) {
        _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];
    }
    return _timer;
}

@end
